/**
 * 时分秒转为时间戳
 * @param {String} time HH-MM-SS
 */
function countDown(time) {
  time = time.replace(/\:/g, '-')
  let s = 0;
  let hour = time.split('-')[0];
  let min = time.split('-')[1];
  let sec = time.split('-')[2];
  s = Number(hour * 3600) + Number(min * 60) + Number(sec);
  return s;
}

/**
 * 替换掉正则匹配到的字符串
 * @param {String} time 时间段
 */
function timeRange(time) {
  if (!Array.isArray(time) || time.length <= 0) {
    return false
  }
  const nowTime =
    new Date().getHours() +
    '-' +
    new Date().getMinutes() +
    '-' +
    new Date().getSeconds()
  if (countDown(time[0]) < countDown(nowTime) && countDown(nowTime) < countDown(time[1])) {
    return true;
  }
  else {
    return false;
  }
}

/**
 * 支出 收入种类
 * type: 0支出 1收入
 */
function getChargeType(type = 1) {
  if (type == 1) {
    // 收入种类
    return [
      { name: '工资', iconCheck: 'https://mmxj.yitanwangluo.cn/income/gongzi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/gongzi-default.png', checked: false },
      { name: '收红包', iconCheck: 'https://mmxj.yitanwangluo.cn/income/shouhongbao-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/shouhongbao-default.png', checked: false },
      { name: '副业', iconCheck: 'https://mmxj.yitanwangluo.cn/income/fuye-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/fuye-default.png', checked: false },
      { name: '奖金', iconCheck: 'https://mmxj.yitanwangluo.cn/income/jiangjing-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/jianging-default.png', checked: false },
      { name: '报销', iconCheck: 'https://mmxj.yitanwangluo.cn/income/baoxiao-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/baoxiao-default.png', checked: false },
      { name: '借入款', iconCheck: 'https://mmxj.yitanwangluo.cn/income/jierukuan-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/jierukuan-default.png', checked: false },
      { name: '零花钱', iconCheck: 'https://mmxj.yitanwangluo.cn/income/linghuaqian-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/linghuaqian-default.png', checked: false },
      { name: '投资收益', iconCheck: 'https://mmxj.yitanwangluo.cn/income/touzishouyi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/touzishouyi-default.png', checked: false },
      { name: '退款', iconCheck: 'https://mmxj.yitanwangluo.cn/income/tuikuan-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/tuikuan-default.png', checked: false },
      { name: '兼职', iconCheck: 'https://mmxj.yitanwangluo.cn/income/jianzhi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/jianzhi-default.png', checked: false },
      // {name:'其他收入',iconCheck:'https://mmxj.yitanwangluo.cn/income/qitashouru-check.png',iconDefault:'https://mmxj.yitanwangluo.cn/income/qitashouyi-default.png',checked:false},
      { name: '生活费', iconCheck: 'https://mmxj.yitanwangluo.cn/income/shenghuofei-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/shenghuofei-default.png', checked: false },
      { name: '收租', iconCheck: 'https://mmxj.yitanwangluo.cn/income/shouzu-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/shouzu-default.png', checked: false },
      { name: '保险收益', iconCheck: 'https://mmxj.yitanwangluo.cn/income/baoxianshouyi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/baoxianshouyi-default.png', checked: false },
      { name: '利息', iconCheck: 'https://mmxj.yitanwangluo.cn/income/lixi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/lixi-default.png', checked: false },
      { name: '股票收益', iconCheck: 'https://mmxj.yitanwangluo.cn/income/gupiaoshouyi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/gupiaoshouyi-default.png', checked: false },
      { name: '其他', iconCheck: 'https://mmxj.yitanwangluo.cn/income/qita-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/income/qita-default.png', checked: false }
    ]
  } else {
    // 支出种类
    return [
      { name: '餐饮', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/canying-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/canyin-default.png', checked: false },
      { name: '购物', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/gouwu-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/gouwu-default.png', checked: false },
      { name: '日用品', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/riyongping-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/riyongping-default.png', checked: false },
      { name: '交通', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/jiaotong-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/jiaotong-default.png', checked: false },
      { name: '蔬菜', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/shucai-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/shucai-default.png', checked: false },
      { name: '水果', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/shuiguo-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/shuiguo-default.png', checked: false },
      { name: '零食', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/lingshi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/lingshi-default.png', checked: false },
      { name: '运动', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/yundong-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/yundong-default.png', checked: false },
      { name: '医疗', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/yiliao-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/yiliao-default.png', checked: false },
      { name: '通讯', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/tongxun-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/tongxun-default.png', checked: false },
      { name: '旅行', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/luxing-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/luxing-default.png', checked: false },
      { name: '物业费', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/wuyefei-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/wuyefei-default.png', checked: false },
      { name: '礼物', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/liwu-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/liwu-default.png', checked: false },
      { name: '学习', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/xuexi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/xuexi-default.png', checked: false },
      { name: '美容', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/meirong-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/meirong-default.png', checked: false },
      { name: '投资', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/touzi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/touzi-default.png', checked: false },
      { name: '社交', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/shejiao-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/shejiao-default.png', checked: false },
      { name: '礼金', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/lijing-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/lijing-default.png', checked: false },
      { name: '服饰', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/fushi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/fushi-default.png', checked: false },
      { name: '娱乐', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/yule-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/yule-default.png', checked: false },
      { name: '快递', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/kuaidi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/kuaidi-default.png', checked: false },
      { name: '保险', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/baoxian-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/baoxian-default.png', checked: false },
      { name: '烟酒', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/yanjiu-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/yanjiu-default.png', checked: false },
      { name: '居家', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/jujia-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/jujia-default.png', checked: false },
      { name: '长辈', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/zhangbei-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/zhangbei-default.png', checked: false },
      { name: '宠物', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/chongwu-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/chongwu-default.png', checked: false },
      { name: '孩子', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/haizi-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/haizi-default.png', checked: false },
      { name: '还款', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/huankaun-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/huankuan-default.png', checked: false },
      { name: '数码', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/shuma-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/shuma-default.png', checked: false },
      { name: '加油', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/jiayou-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/jiayou-default.png', checked: false },
      { name: '住房', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/zhufang-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/zhufang-default.png', checked: false },
      { name: '汽车', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/qiche-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/qiche-default.png', checked: false },
      { name: '水电煤', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/shuidianmei-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/shuidianmei-default.png', checked: false },
      { name: '维修', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/weixiu-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/weixiu-default.png', checked: false },
      { name: '其他', iconCheck: 'https://mmxj.yitanwangluo.cn/disburse/qita-check.png', iconDefault: 'https://mmxj.yitanwangluo.cn/disburse/qita-default.png', checked: false }
    ]
  }
}

function formatDate(value, args) {
  let dt = new Date(value);
  if (args == 'HH:mm') {// M月d日
    let hour = dt.getHours().toString().padStart(2, '0');
    let minute = dt.getMinutes().toString().padStart(2, '0');
    return `${hour}:${minute}`;
  } else if (args == 'M月d日') {// M月d日
    let month = dt.getMonth() + 1;
    let date = dt.getDate();
    return `${month}月${date}日`;
  } else if (args == 'yyyy年M月') {// yyyy年M月
    let year = dt.getFullYear();
    let month = dt.getMonth() + 1;
    return `${year}年${month}月`;
  } else if (args == 'yyyy-M-d') {// yyyy-M-d
    let year = dt.getFullYear();
    let month = dt.getMonth() + 1;
    let date = dt.getDate();
    return `${year}-${month}-${date}`;
  } else if (args == 'yyyy-M-d H:m:s') {// yyyy-M-d H:m:s
    let year = dt.getFullYear();
    let month = dt.getMonth() + 1;
    let date = dt.getDate();
    let hour = dt.getHours();
    let minute = dt.getMinutes();
    let second = dt.getSeconds();
    return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
  } else if (args == 'yyyy-MM-dd') {// yyyy-MM-dd
    let year = dt.getFullYear();
    let month = (dt.getMonth() + 1).toString().padStart(2, '0');
    let date = dt.getDate().toString().padStart(2, '0');
    return `${year}-${month}-${date}`;
  } else if (args == 'yyyy-MM') {// yyyy-MM
    let year = dt.getFullYear();
    let month = (dt.getMonth() + 1).toString().padStart(2, '0');
    return `${year}-${month}`;
  } else {// yyyy-MM-dd HH:mm:ss
    let year = dt.getFullYear();
    let month = (dt.getMonth() + 1).toString().padStart(2, '0');
    let date = dt.getDate().toString().padStart(2, '0');
    let hour = dt.getHours().toString().padStart(2, '0');
    let minute = dt.getMinutes().toString().padStart(2, '0');
    let second = dt.getSeconds().toString().padStart(2, '0');
    return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
  }
}

export default {
  timeRange,
  getChargeType,
  formatDate
}